package mobi.weq.servlets.user;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import mobi.weq.dao.UserDao;

/**
 * Servlet implementation class RegisterUser
 */
@WebServlet("/user/checkusername")
public class CheckUsername extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String username = request.getParameter("username");
		if (username != null) {
			UserDao ud = new UserDao();
			try {
				boolean yes = ud.doesUsernameExists(username);
				response.getWriter().print("{\"success\":" + yes + "}");

			} catch (SQLException e) {
				System.out.println(e);
			}
		}
	}

}
